package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;
    @GetMapping
    public Result list(Integer channel, Integer type, Integer status,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        PageResult<Activity> pageResult = activityService.list(channel, type, status, page, pageSize);
        return Result.success(pageResult);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        activityService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        activityService.addActivity(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }

    @PutMapping
    public Result update(@RequestBody Activity activity){
        activityService.Update(activity);
        return Result.success();
    }

    @GetMapping("type/{type}")
    public Result getByType(@PathVariable Integer type){
        List<Activity> list = activityService.getByType(type);
        return Result.success(list);
    }
}
